class Solution {
public:
    int reverse(int x) {
        string temp = to_string(x);
        int left = (temp[0] == '-') ? 1 : 0;
        int right = temp.size()-1;

        while(left < right)
        {
            swap(temp[left++], temp[right--]);
        }

        long long res = stoll(temp);
        if(res > INT_MAX || res < INT_MIN)
            return 0;
        return (int)res;
    }
};